import axios from 'utils/axios';
import updateManager from './common/updateManager';

App({
  onLaunch: function () {
    const openid = wx.getStorageSync('openid');
    const that = this;
    if(!openid){
      wx.login({
        success: (res) => {
          axios.get("/app/getOpenid",{
            js_code:res.code
          }).then(res=>{
            const openid = JSON.parse(res.data).openid;
            wx.setStorageSync("openid",openid)
            return openid;
          }).then(openid =>{
            that.queryMemberInfo(openid);
          })
        },
      })
    }else{
      that.queryMemberInfo(openid);
    }
    
  },
  queryMemberInfo(openid){
    const memberInfo = JSON.parse(wx.getStorageSync('memberInfo') ||"{}");
    if(!memberInfo.ID){
      axios.get("/app/memberList",{
        wxId:openid
      }).then(res=>{
        if(res.data.length>0){
          wx.setStorageSync('memberInfo', JSON.stringify(res.data[0]))
        }
      })
    }
  },
  onShow: function () {
    updateManager();
  },
  globalData:{
    orderDetail:{}
  }
});
